{% extends 'main.html' %}
{% load func %}

{% block title %}
    <title>asset info</title>
{% endblock %}


{% block content %}
<div class="panel">
    <div class="panel-heading">
        <h3 class="panel-title">事件详情页</h3>
    </div>

    <!--Bordered Table-->
    <!--===================================================-->
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th class="text-center">时间</th>
                        <th>主机</th>
                        <th>内容</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                {% for info_obj in obj %}
                    <tr>
                        <td class="text-center">{{ info_obj.update_time }}</td>
                        <td>{{ info_obj.asset.server.hostname }}</td>
                        <td>{{ info_obj.content }}</td>
                        {% if query_string == 'status=3'  %}
                            {% if info_obj.type != 0 %}
                                {% if info_obj.action != 0 %}
                                    <td><button class="btn btn-warning" onclick="return del_envent({{ info_obj.id }})">删除事件</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-danger" onclick="return del_physical({{ info_obj.r_id }},{{ info_obj.type }},{{ info_obj.id }})">移除硬件</button></td>
                                {% else %}
                                    <td><button class="btn btn-warning" onclick="return del_envent({{ info_obj.id }})">删除事件</button></td>
                                {% endif %}
                            {% else %}
                                <td><button class="btn btn-warning" onclick="return del_envent({{ info_obj.id }})">删除事件</button></td>
                            {% endif %}
                        {% else %}

                            <td><button class="btn btn-warning" onclick="return del_envent({{ info_obj.id }})">删除事件</button></td>
                        {% endif %}
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

</div>
<script>
    function del_envent(id){
        if(confirm('是否删除该事件，删除后将不会收到此事件的所有告警信息！')){
            console.log('del')
        }
        else {
            return false
        }
        $.ajax({
            url:'/',
            type:'DELETE',
            data:{'envent_id':id},
            success:function(arg){
                location.reload()
            }
        })
    }

    function del_physical(physical_id,physical_type,envent_id){
          if(confirm('是否从数据库删除该硬件所有信息！！')){
            console.log('del')
        }
        else {
            return false
        }
        $.ajax({
            url:'/',
            type:'DELETE',
            data:{'physical_id':physical_id,'physical_type':physical_type,'envent_id':envent_id},
            success:function(arg){
                location.reload()
            }
        })
    }
</script>
{% endblock %}
